package com.athu.study.controller;

import dev.langchain4j.data.message.UserMessage;
import dev.langchain4j.model.chat.ChatModel;
import dev.langchain4j.model.chat.response.ChatResponse;
import dev.langchain4j.model.output.TokenUsage;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class LowApiController {
    @Resource(name = "qwen")
    private ChatModel chatModelQwen;
    @Resource(name = "deepseek")
    private ChatModel chatModelDeepSeek;
    @GetMapping("/lowapi/qwen")
    public String MultiModelQwen(@RequestParam(value = "prompt",defaultValue = "你是谁")String prompt){
        String result = chatModelQwen.chat(prompt);
        System.out.println("通过langchain4j调用模型返回结果:"+result);
        return  result;
    }
    @GetMapping("/lowapi/deepseek")
    public String MultiModelDeepSeek(@RequestParam(value = "prompt",defaultValue = "你是谁")String prompt){
        ChatResponse chat = chatModelDeepSeek.chat(UserMessage.from(prompt));
        String result = chat.aiMessage().text();
        System.out.println("通过langchain4j调用模型返回结果:"+result);
        TokenUsage tokenUsage = chat.tokenUsage();
        System.out.println("本次调用消耗token"+tokenUsage);
        result=result +"\t\n"+ tokenUsage;
        return result;
    }
}
